Creating an Inputs Class
What is in an inputs class?
An inputs class can be built in two ways:
- All the class does is hold each input as a variable. An example of this is our DriveTrainSubsystemInputs class from BaseSwerve2025:
package frc.robot.LogInputs;
import org.littletonrobotics.junction.AutoLog;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
@AutoLog
public class DrivetrainInputs {
public SwerveModulePosition[] swerveModulePositions = new SwerveModulePosition[4];
public SwerveModuleState[] swerveModuleStates = new SwerveModuleState[4];
public Rotation2d gyroScopeRotation = new Rotation2d();
public double pitch;
public double roll;
public double gyroTimeStamp;
public double angularVelocity;
}
This class stores each input variable we have for our drivetrain. The @AutoLog annotation above the class decleration is required. This will cause the annotation processor to create a new class whenever you build the code. This auto-generated class will take care of accessing the log file to send and recieve logged inputs.
- Create your own class that both holds the variables (like the DriveTrainSubsystemInputs class) and also handles the sending and recieving of logged inputs from the log file. An example of this is our LimelightInputs class from BaseSwerve2025. When doing this, you must have the variables stated under the class decleration (just like above) but also have two methods in the class: toLog() and fromLog()
These methods are automatically generated by the annotation processor in the automatically created class, but we had to implement them into our class instead becuase we wanted to log Pose2d's which created errors becuase the automatically created class used these lines:
table.put("MegaTag2Pose2d", megaTag2Pose2d);
and
table.get("MegaTag2Pose2d", megaTag2Pose2d);
This created compilation errors becuase an input of the Object type was needed to log a Pose2d, so in our own class we used the lines:
table.put("MegaTag2Pose2d", Pose2d.struct, megaTag2Pose2d);
and
table.get("MegaTag2Pose2d", Pose2d.struct, megaTag2Pose2d);
How to create an inputs class
We use a folder called LogInputs folder to store our input classes. Each input class represents the inputs from one area of the robot - usually a subsystem. An example of this is the Coral End Effector subsystem. For this subsystem's inputs class, one might add a MotorLoggerInputs for the motor, along with a variable that represents the status of the distance sensor in the subsystem.
If the inputs class will only hold variables (option 1 above), then the annotation @AutoLog must be added above the class declaration. If the inputs class will also handle the sending and recieving of inputs to/from the log file, then add
implements LoggableInputs
next step
After an inputs class is created, the inputs class must now be incorporated into the associated subsystem. This involves making sure the inputs are updated periodically, and referencing the inputs class whenver the inputs are used